object TestGeneric {
  def main(args: Array[String]): Unit = {
    //特殊的模式匹配1   打印元组第一个元素
    for (elem <- Array(("a", 1), ("b", 2), ("c", 3))) {
      println(elem._1)
    }
    for ((word, count) <- Array(("a", 1), ("b", 2), ("c", 3))) {
      println(word)
    }
    for ((word, _) <- Array(("a", 1), ("b", 2), ("c", 3))) {
      println(word)
    }
    for (("a", count) <- Array(("a", 1), ("b", 2), ("c", 3))) {
      println(count)
    }
    println("--------------")
    //特殊的模式匹配2 给元组元素命名
    val (id, name, age): (Int, String, Int) = (100, "zs", 20)
    println((id, name, age))
    println("--------------")
    //特殊的模式匹配3   遍历集合中的元组，给count * 2
    val list: List[(String, Int)] = List(("a", 1), ("b", 2), ("c", 3))
    //println(list.map(t => (t._1, t._2 * 2)))
    println(
      list.map {
        case (word, count) => (word, count * 2)
      }
    )
    val list1 = List(("a", ("a", 1)), ("b", ("b", 2)), ("c", ("c", 3)))
    println(
      list1.map {
        case (_, (word, count)) => (word, count * 2)
      }
    )
    /** 8.5 for 表达式中的模式匹配 */
    val map = Map("A" -> 1, "B" -> 0, "C" -> 3)
    for ((k, v) <- map) { //直接将map中的k-v遍历出来
      println(k + " -> " + v) //3个
    }
    println("----------------------")
    //遍历value=0的 k-v ,如果v不是0,过滤
    for ((k, 0) <- map) {
      println(k + " --> " + 0) // B->0
    }
    println("----------------------")
    //if v == 0 是一个过滤的条件
    for ((k, v) <- map if v >= 1) {
      println(k + " ---> " + v) // A->1 和 c->33
    }


  }
}
